<template>
	<view class="container ptb_8 plr_16">
		<view class="pt_12 plr_12 pb_16 bc_fff br_12">
			<view>
				提现数量
			</view>
			<view class="mt_25 fx aib jcb pb_12 bob_1 boc_grey">
				<view class="fx aib fx_1" @click="KeyboarOpen">
					<text class="fb">￥</text>
					<text class="ml_4 fz_20  fc_ccc" :style="[numberStyle]">{{numberInput}}</text>
				</view>
				<text class="fz_12 fc_999">金豆</text>
			</view>
			<view class="mt_14 fz_12 fc_999">
				最低提现额度：{{rule.minWithdraw||0}}金豆，最高提现额度：{{rule.maxWithdraw||0}}金豆
			</view>
		</view>
		<view class="fz_12 mt_12">
			每周{{weekStr}}可提现;1金豆可提现金额为{{rule.ratio||''}}元
		</view>
		<view class="mt_48">
			<button class="custom_btn primary lh_40 w100 fz_14 br_40 fb" @click="handleConfirm" style="background: #E4C78C;">申请提现</button>
		</view>
		<NumberKeyboard tabBar data-key="number" ref='KeyboarHid' otherNum="." @input='handleInputNum' :psdLength="10">
		</NumberKeyboard>
	</view>
</template>

<script>
	import NumberKeyboard from '@/components/number-keyboard/number-keyboard.vue'
	import api from '@/service/config/api'
	export default {
		components: {
			NumberKeyboard,
		},
		data() {
			return {
				select: null, // 选择项
				number: '', // 输入数字
				disabled: false, // 是否禁止
				integral: 0, // 剩余积分
				dataInfo: {},
				rule: {},
			}
		},
		computed: {
			numberStyle() {
				return this.number != '' ? {
					color: '#333',
					fontSize: '64rpx'
				} : {}
			},
			numberInput() {
				return this.number != '' ? this.number : '请输入提现金豆数量'
			},
			weekStr() {
				const arr = ['', '一', '二', '三', '四', '五', '六', '日']
				return arr[this.rule.week] || ''
			}
		},
		onShow() {
			this.getAllData()
		},
		methods: {
			getAllData() {
				this.$utils.loading()
				Promise.all([this.getCoinRule(), this.getData()]).then(() => {
					uni.hideLoading()
				})
			},
			getCoinRule() {
				return new Promise(resolve => {
					api.get('/base/api/tCurrencySet/item/get', {}, {
						noHideLoading: true
					}).then(res => {
						this.rule = res.data
					}).finally(() => {
						resolve()
					})
				})
			},
			getData() {
				return new Promise(resolve => {
					api.get('/user/api/myLegumes', {}, {
						noHideLoading: true
					}).then(res => {
						this.dataInfo = res.data
					}).finally(() => {
						resolve()
					})
				})
			},
			//打开键盘
			KeyboarOpen(e) {
				this.$refs.KeyboarHid.open();
			},
			//输入的值
			handleInputNum(val) {
				this.number = val;
			},
			handleConfirm() {
				if (this.$moment().day() != this.rule.week) {
					return this.$utils.showToast(`当前时间不可提现，提现日为每周${this.weekStr}`)
				}
				if (!this.number) {
					return this.$utils.showToast(`请输入提现数量`)
				}
				if (this.dataInfo.youJiaBalance < this.number * 1) {
					return this.$utils.showToast('金豆不足')
				}
				if ((this.number * 1 < this.rule.minWithdraw)) {
					return this.$utils.showToast('低于提现范围')
				}
				if ((this.number * 1 > this.rule.maxWithdraw)) {
					return this.$utils.showToast('高于提现范围')
				}
				this.$utils.loading()
				api.post('/user/api/myLegumes/cash', {
					legumesNum: this.number
				}).then(() => {
					uni.redirectTo({
						url: '/pages/common/pages/success?type=withdraw'
					})
				})
			}
		},
	}
</script>

<style lang="scss">
	.container {}
</style>